<?php
require_once("log.php");

/**
 * Select request method
 */
$_method = strtoupper($_SERVER['REQUEST_METHOD']);
switch($_method) {
	case 'GET':
		get();
		break;
	case 'POST':
		post();
		break;
	case 'PUT':
		put();
		break;
	case 'DELETE':
		delete();
		break;		
}

  // for google code test string //

/**
 * Get Database data
 */
function DBquery($str) {
	$dsn = "sqlite:db/test.db";
	$db = new PDO($dsn);
	if(!$db)
		die("error");
	$result = $db->query($str)->fetchall();
	sqlite_close($db);
	return $result;	
}

function proxy() {
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, "http://192.168.100.110/secgate-rest/hw");
	curl_setopt($ch, CURLOPT_HEADER, false);
	$data = curl_exec($ch);	
	curl_close($ch);
	return $data;
}

function parseData($data) {
	$len = count($data);
	for($i=0;$i<$len;$i++) {
		$data1[$i]['uid'] = $data[$i]['uid'];
		$data1[$i]['password'] = $data[$i]['password'];
		$data1[$i]['name'] = $data[$i]['name'];
		$data1[$i]['arg'] = $data[$i]['arg'];
	}
	return $data1;
}

/**
 * HTTP Request
 */
function get() {
	$data = array("key" => "value");
	echo json_encode($data);
}

function post() {
	$post = array();
	parse_str(file_get_contents('php://input'), $post);
	echo json_encode($post);
}
function put() {
	return;
}
function delete() {
	return;
}

?>
